package cc.atliberty.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/ListCart")
public class ListCart extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        HttpSession session = request.getSession(false);
        if (null == session){
            out.println("您的购物车为空");
            return;
        }
        out.println("您购买的商品如下：<br/>");
        List<Book> list = (List<Book>) session.getAttribute("list");

        for (Book book : list){
            out.println(book.getName() + "<br/>");
        }
    }
}
